<template>
<div style="font-size: 12px;line-height: 60px;display: flex "
      >
  <div style="flex:1;font-size: 18px"  >
    <span :class="collapseBtnClass" style="cursor: pointer" @click="collapse"></span>

      <el-breadcrumb separator="/" style="display: inline-block;margin-left: 10px">
        <el-breadcrumb-item :to="'/'">首页</el-breadcrumb-item>
        <el-breadcrumb-item >{{currentPathName}}</el-breadcrumb-item>
      </el-breadcrumb>
  </div>
  <el-dropdown style="width:150px; cursor:pointer;text-align: right">
    <div style="display: inline-block">
      <img :src="user.avatarUrl" @click="open"
           alt="" style="width: 35px;height: 35px ;border-radius:50%;position: relative;top: 10px;right: 5px">
      <span @click="open">{{ user.nickname }}</span><i class="el-icon-caret-bottom" @click="open"></i>
    </div>
    <el-dropdown-menu></el-dropdown-menu>
  </el-dropdown>
  <el-dialog  :visible.sync="openDialog" width="31%" height="50%" style="opacity: 1;background-color: #42b983">
    <div>
      <el-image :src="user.avatarUrl"  style="width: 140px;height: 140px;
        border-radius: 50%;border: 5px solid brown;
        position: relative;right: -155px " title="个人头像">
      </el-image>
    </div>
    <div>
      <el-button @click="openDialog = false" style="font-size: 30px;position: relative;right: -115px" type="primary" plain>
        <i class="el-icon-lock"> </i>
        <router-link to="/modify" style="text-decoration: none;color:black">
          密 码 修 改
        </router-link>
      </el-button>
    </div>
    <div>
      <el-button @click="openDialog = false" style="font-size: 30px;position: relative;right: -115px" type="primary" plain>
        <i class="el-icon-user-solid"> </i>
        <router-link to="/person" style="text-decoration: none;color:black">
          个 人 信 息
        </router-link>
      </el-button>
    </div>
    <div>
      <el-button @click="openDialog = false" style="width:120px;font-size: 30px;position: relative;right: -161px" type="danger" plain>
          <span @click="lagout" style="text-decoration: none;color:black" to>
            退出
            <i class="el-icon-circle-close"></i>
          </span>
      </el-button>
    </div>
  </el-dialog>

</div>
</template>

<script>
export default {
  name: "Header",
  props:{
    collapseBtnClass:String,
    collapse:Function,
    pathName:String,
  },
  watch:{//监听路由变化
    '$route':function (){
      this.currentPathName=localStorage.getItem("currentPathName")
    }
  },
  data(){
    return{
      currentPathName:'',
      openDialog:false,
      user: localStorage.getItem("user")?JSON.parse(localStorage.getItem("user")):{}
    }
  },
  methods:{
    lagout(){
      this.$router.push("/login")
      localStorage.removeItem("user")
      localStorage.removeItem("menus")
      this.$message.success("退出成功")
    },
    open(){
      this.openDialog=true
    }
  }
}
</script>
